#!/bin/bash
#/*
 #* com.nathulal.AdBlockToggle.patchhelper
 #* 
 #* Copyright (c) 2009 nathulal <inathulal at gmail.com>. All rights reserved.
 #* 
 #* This file is part of iPhoneAdBlockToggle.
 #* 
 #* iPhoneAdBlockToggle is free software: you can redistribute it and/or modify
 #* it under the terms of the GNU General Public License as published by
 #* the Free Software Foundation, either version 3 of the License, or
 #* (at your option) any later version.
 #* 
 #* iPhoneAdBlockToggle is distributed in the hope that it will be useful,
 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #* GNU General Public License for more details.
 #* 
 #* You should have received a copy of the GNU General Public License
 #* along with iPhoneAdBlockToggle.  If not, see <http://www.gnu.org/licenses/>.
 #*/
 
m_username=`whoami|grep .`
if [ "$m_username" != "root" ]
then
	echo "You must be logged in as root."
	exit
fi;

if [ ! -f /tmp/AdBlock-patchhelper.pid ]
then

	echo "Patching adblock checking apps ..." > /tmp/AdBlock-patchhelper.pid

	echo "Begin patching ..."

	if [ -f /Applications/SBSettings.app/SBSettings ]
	then
		echo "Patching SBSettings ..."
		killall SBSettings
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/SBSettings.app/SBSettings
		ldid -S /Applications/SBSettings.app/SBSettings
		echo "Patched SBSettings"
	fi;

	if [ -f /Applications/Categories.app/Categories ]
	then
		echo "Patching Categories ..."
		killall Categories
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/Categories.app/Categories
		ldid -S /Applications/Categories.app/Categories
		echo "Patched Categories"
	fi;
	
	if [ -f /Applications/Lockdown.app/Lockdown ]
	then
		echo "Patching Lockdown ..."
		killall Lockdown
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/Lockdown.app/Lockdown
		ldid -S /Applications/Lockdown.app/Lockdown
		echo "Patched Lockdown"
	fi;
	
	if [ -f /Applications/BossPrefs.app/BossPrefs ]
	then
		echo "Patching BossPrefs ..."
		killall BossPrefs
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/BossPrefs.appBossPrefs
		ldid -S /Applications/BossPrefs.app/BossPrefs
		echo "Patched BossPrefs"
	fi;
	
	if [ -f /Applications/BossPaper.app/BossPaper ]
	then
		echo "Patching BossPaper ..."
		killall BossPaper
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/BossPaper.app/BossPaper
		ldid -S /Applications/BossPaper.app/BossPaper
		echo "Patched BossPaper"
	fi;
	
	if [ -f /Applications/Docs.app/Docs2 ]
	then
		echo "Patching Docs2 ..."
		killall Docs2
		/var/mobile/Library/SBSettings/Toggles/AdBlock/patchhelper /Applications/Docs.app/Docs2
		ldid -S /Applications/Docs.app/Docs2
		echo "Patched Docs2"
	fi;
	
	rm /tmp/AdBlock-patchhelper.pid
	echo "Done. If you have trouble launching a patched app reload the SpringBoard and then try patching again."
fi;

